21. EKF Algorithm Generalization
EKF Algortihm Generalization
Extended Kalman Filter Equations
Although the mathematical proof is somewhat complex, it turns out that the Kalman filter equations and extended Kalman filter equations are very similar. The main differences are:
- the matrix will be replaced by when calculating .
- the matrix in the Kalman filter will be replaced by the Jacobian matrix when calculating , , and .
- to calculate , the prediction update function, , is used instead of the matrix.
- to calculate , the function is used instead of the matrix.
For this project, however, we do not need to use the function or . If we had been using a non-linear model in the prediction step, we would need to replace the matrix with its Jacobian, . However, we are using a linear model for the prediction step. So, for the prediction step, we can still use the regular Kalman filter equations and the matrix rather than the extended Kalman filter equations.
The measurement update for lidar will also use the regular Kalman filter equations, since lidar uses linear equations. Only the measurement update for the radar sensor will use the extended Kalman filter equations.
One important point to reiterate is that the equation for the Kalman filter does not become for the extended Kalman filter. Instead, for extended Kalman filters, we'll use the h function directly to map predicted locations from Cartesian to polar coordinates.

The comparison for reference.
Clarification of u = 0
In the above image, the prediction equation is written as and . Previously the equation was written .
It is just a question of notation where is the greek letter "nu" and "u" is used in the code examples. Remember that is represented by a gaussian distribution with mean zero. The equation or the equivalent equation calculates the mean value of the state variable ; hence we set u = 0. The uncertainty in the gaussian distribution shows up in the matrix.
More Details About Calculations with Radar Versus Lidar
In the radar update step, the Jacobian matrix is used to calculate , and . To calculate , we use the equations that map the predicted location from Cartesian coordinates to polar coordinates:
The predicted measurement vector is a vector containing values in the form . The radar sensor will output values in polar coordinates:
In order to calculate for the radar sensor, we need to convert to polar coordinates. In other words, the function maps values from Cartesian coordinates to polar coordinates. So the equation for radar becomes .
One other important point when calculating with radar sensor data: the second value in the polar coordinate vector is the angle . You'll need to make sure to normalize in the vector so that its angle is between and ; in other words, add or subtract from until it is between and .
To summarize:
- for measurement updates with lidar, we can use the matrix for calculating , , and .
- for radar, is used to calculate , and .